const HtmlWebpackPlugin = require('html-webpack-plugin');
var { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
  mode: 'development',
  entry: {
    main: './src/index.js',
    other: './src/other.js',
  },
  output: {
    filename: 'js/[name].[chunkhash:5].js',
    publicPath: '/',
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader?modules'],
      },
      {
        test: /\.jpg$/,
        use: {
          loader: 'file-loader',
          options: {
            name: 'img/[hash:5].[ext]',
          },
        },
      },
    ],
  },
  devServer: {
    open: true,
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
    new MiniCssExtractPlugin({
      // `output.filename`的含义一样，即根据chunk生成的样式文件名
      // 默认情况下，每个chunk对应一个css文件
      filename: 'css/[name].[contenthash:5].css',
    }),
  ],
};
